public class demo9 {
    public static boolean Q = false;

    public static void main(String[] args) {

        Thread t = new Thread(() -> {
            while(!Q){
                System.out.println("hello t!");

                try{
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t.start();

        try{
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Q = true;
    }
}
